<?php		
	function show_interface () {
		require_once('page.inc');
		require_once('paths.inc');
		require_once('utils.inc');		
		require_once(INCLUDE_PATH.'constants.inc');
		
		session_start();
		checkIsLoggedIn();
		select_language();
		
		if (isset($_GET['id_rezultat'])) $id_rezultat = $_GET['id_rezultat'];
		if (isset($_GET['tip'])) $tip = $_GET['tip'];
		if (isset($_GET['tip_loc'])) $tip_loc = $_GET['tip_loc'];
        if (isset($_GET['index'])) $index = $_GET['index'];
        
        
        if ($tip_loc == CT_ADRESA_COMANDA_DESCARCARE) 
			$adrRequired = 'true';
		else
			$adrRequired = 'false';

		$opt = "insert";
		
		if (isset($index)) {
			
			if ($tip_loc == CT_ADRESA_COMANDA_VAMA_IMPORT) {
				$adresa = $_SESSION['comanda']->adrese_vama_import[$index];	
			}						
			if ($tip_loc == CT_ADRESA_COMANDA_VAMA_EXPORT) {
				$adresa = $_SESSION['comanda']->adrese_vama_export[$index];	
			}
			if ($tip_loc == CT_ADRESA_COMANDA_INCARCARE) {
				$adresa = $_SESSION['comanda']->adrese_incarcare[$index];	
			}
			if ($tip_loc == CT_ADRESA_COMANDA_DESCARCARE) {
				$adresa = $_SESSION['comanda']->adrese_descarcare[$index];	
			}
			$opt = "update";
			$text = LANG_Update;
		}
		else {
			$index = -1;
			$text = LANG_Add;
			$adresa = new Address(null, null, null, null, null, null, null, null);
		}
		
        $titlu_modal = '';
        if ($index != -1) {
            if ($tip_loc == CT_ADRESA_COMANDA_DESCARCARE) {
                $titlu_modal = LANG_Editeaza_descarcare;
                $help_text = LANG_EXTRA_MODAL_EDIT_ADRESA_DESCARCARE;
            }
            if ($tip_loc == CT_ADRESA_COMANDA_INCARCARE) {
                $titlu_modal = LANG_Editeaza_incarcare;
                $help_text = LANG_EXTRA_MODAL_EDIT_ADRESA_INCARCARE;
            }
            if ($tip_loc == CT_ADRESA_COMANDA_VAMA_IMPORT) {
                $titlu_modal = LANG_Editeaza_vama_import;
                $help_text = LANG_EXTRA_MODAL_EDIT_ADRESA_VAMA_IMPORT;
            }
            if ($tip_loc == CT_ADRESA_COMANDA_VAMA_EXPORT) {
                $titlu_modal = LANG_Editeaza_vama_export;
                $help_text = LANG_EXTRA_MODAL_EDIT_ADRESA_VAMA_EXPORT;
            }
        }
        else {
            if ($tip_loc == CT_ADRESA_COMANDA_DESCARCARE) {
                $titlu_modal = LANG_Adauga_descarcare;
                $help_text = LANG_EXTRA_MODAL_ADD_ADRESA_DESCARCARE;
            }
            if ($tip_loc == CT_ADRESA_COMANDA_INCARCARE) {
                $titlu_modal = LANG_Adauga_incarcare;
                $help_text = LANG_EXTRA_MODAL_ADD_ADRESA_INCARCARE;
            }
            if ($tip_loc == CT_ADRESA_COMANDA_VAMA_IMPORT) {
                $titlu_modal = LANG_Adauga_vama_import;
                $help_text = LANG_EXTRA_MODAL_ADD_ADRESA_VAMA_IMPORT;
            }
            if ($tip_loc == CT_ADRESA_COMANDA_VAMA_EXPORT) {
                $titlu_modal = LANG_Adauga_vama_export;
                $help_text = LANG_EXTRA_MODAL_ADD_ADRESA_VAMA_EXPORT;
            }
        }

		$ret = '<div align="center">			
				<table name="adresa" border="0" align="center" id="wrapper2" cellpaddin="2" cellspacing="0">
					<thead>
						<tr>
							<th colspan="4">' . $titlu_modal . '</b></th>
						</tr>
					</thead>';
        if ($tip_loc == CT_ADRESA_COMANDA_INCARCARE || $tip_loc == CT_ADRESA_COMANDA_DESCARCARE)
            $ret .= '
                        <tr class="capTabel">
                            <td id="td_data" align="right"><b>' . LANG_Data_si_ora . '</b></td>
                            <td align="left">'.render_date_field_with_ora_button($adresa->data, 'data', 'DHTMLSuite_modalBox_contentDiv').'</td>
                            <td id="td_data_efectiva" align="right"><b>' . LANG_Data_si_ora_efectiva . '</b></td>
                            <td align="left">'.render_date_field_with_ora_button($adresa->data_efectiva, 'data_efectiva', 'DHTMLSuite_modalBox_contentDiv').'</td>
                        </tr>';
        $ret .= '
					<tr class="capTabel">
						<td id="td_adresa" align="right"><b>' . LANG_ADRESA . '</b></td>
						<td align="left"><textarea name="adresa" id="adresa" class="input_textarea_modal_adresa">' . $adresa->adresa . '</textarea>
                        <td id="td_alte_mentiuni" align="right"><b>' . LANG_Alte_mentiuni . '</b></td>
                        <td align="left"><textarea name="alte_mentiuni" id="alte_mentiuni" class="input_textarea_modal_adresa">' . $adresa->alte_mentiuni . '</textarea>
					</tr>
					<tr class="capTabel">
						<td id="td_oras" align="right"><b>' . LANG_ORAS . CT_OBLIGATORIU . '</b></td>
						<td align="left"><input type="text" name="oras" id="oras" value="' . $adresa->oras .'" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" /></td>
                        <td id="td_nume_contact" align="right"><b>' . LANG_Nume_contact . '</b></td>
                        <td align="left"><input type="text" name="nume_contact" id="nume_contact" value="' . $adresa->nume_contact . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
					</tr>
					<tr class="capTabel">
						<td id="td_judet" align="right"><b>' . LANG_JUDET . '</b></td>
						<td align="left"><input type="text" name="judet" id="judet" value="' . $adresa->judet . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                        <td id="td_tel_contact" align="right"><b>' . LANG_Telefon_contact . '</b></td>
                        <td align="left"><input type="text" name="tel_contact" id="tel_contact" value="' . $adresa->tel_contact . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
					</tr>		
					<tr class="capTabel">
						<td id="td_cod_postal" align="right"><b>' . LANG_COD_POSTAL . '</b></td>
						<td align="left"><input type="text" name="cod_postal" id="cod_postal" value="' . $adresa->cod_postal . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                ';
        if ($tip_loc == CT_ADRESA_COMANDA_INCARCARE || $tip_loc == CT_ADRESA_COMANDA_DESCARCARE)
            $ret .= '       
                            <td id="td_tip_marfa" align="right"><b>' . LANG_Tip_marfa . '</b></td>
                            <td align="left"><input type="text" name="tip_marfa" id="tip_marfa" value="' . $adresa->tip_marfa . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                    ';
        else
            $ret .= '       
                            <td id="td_nume_birou_vamal" align="right"><b>' . LANG_Nume_birou_vamal . '</b></td>
                            <td align="left"><input type="text" name="nume_birou_vamal" id="nume_birou_vamal" value="' . $adresa->nume_birou_vamal . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                    ';
        $ret .= '
					</tr class="capTabel">	        
                ';
        $ret .= '
                    <tr class="capTabel">
                        <td id="td_tara" align="right"><b>' . LANG_TARA . CT_OBLIGATORIU . '</b></td>
                        <td align="left"><input type="text" name="tara" id="tara" value="' . $adresa->tara . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                ';
        if ($tip_loc == CT_ADRESA_COMANDA_INCARCARE || $tip_loc == CT_ADRESA_COMANDA_DESCARCARE)
            $ret .= '
                            <td id="td_nr_colete" align="right"><b>' . LANG_Nr_colete . '</b></td>
                            <td align="left"><input type="text" class="input_number" name="nr_colete" id="nr_colete" value="' . prepareFloatForUser($adresa->nr_colete) . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                    ';
        else
            $ret .= '
                        <td id="td_cod_vama" align="right"><b>' . LANG_Cod_vama . '</b></td>
                        <td align="left"><input type="text" name="cod_vama" id="cod_vama" value="' . $adresa->cod_vama . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                ';
        $ret .= '                        
                    </tr>';
                    
        if ($tip_loc == CT_ADRESA_COMANDA_VAMA_EXPORT || $tip_loc == CT_ADRESA_COMANDA_VAMA_IMPORT)
            $label = LANG_Comisionar_vamal;
        else
            $label = LANG_NUME_FIRMA;
		$ret .= '<tr class="capTabel">
					<td id="td_nume_firma" align="right"><b>' . $label . '</b></td>
					<td align="left"><input type="text" name="nume_firma" id="nume_firma" value="' . $adresa->nume_firma . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" /></td>
                ';
                
        if ($tip_loc == CT_ADRESA_COMANDA_VAMA_EXPORT || $tip_loc == CT_ADRESA_COMANDA_VAMA_IMPORT) {
            if ($tip_loc == CT_ADRESA_COMANDA_VAMA_IMPORT)
                $label = LANG_Importator;
            else
                $label = LANG_Exportator;
                
            $ret .= '
                    <td id="td_impexp" align="right"><b>' . $label . '</b></td>
                    <td align="left"><input type="text" name="impexp" id="impexp" value="' . $adresa->impexp . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" /></td>
                    ';
        }
        else
            $ret .= '
                    <td id="td_greutate" align="right"><b>' . LANG_Greutate . '</b></td>
                    <td align="left"><input type="text" name="greutate" id="greutate" value="' . $adresa->greutate . '" size="' . CT_MODAL_ADDRESA_INPUT_SIZE_TEXT_BOX . '" />
                    ';
                    
        $ret .= '</tr>';
            
        if ($tip_loc != CT_ADRESA_COMANDA_INCARCARE) {
            $ret .= '<tr class="capTabel">
                        <td id="td_legatura_incarcare" align="right"><b>'
                        . LANG_Locuri_incarcare . '</b></td>
                        <td align="left" colspan="3">';

            $legaturi = explode(";", $adresa->legatura_incarcare);
            $i = 0;
            foreach($_SESSION['comanda']->adrese_incarcare as $incarcare) {
                // Nu afisam checkbox pt adresele sterse
                if ($incarcare->status != CT_CONTACT_DELETED) {
                    $i++;
                    if (in_array($i, $legaturi))
                        $checked = 'checked = "checked"';
                    else
                        $checked = '';
                    $ret .= $i. '. '. $incarcare->oras.'<input type="checkbox" id="loc' . $i . '" value="'.$i.'"' . $checked.'"/> ';
                }
            }
            if ($i == 0)
                $ret .= LANG_NICI_UN_LOC_INCARCARE_DEFINIT;
            $ret .= '</td>
                </tr>';
        }
            
		$ret .=	'<tr class="capTabel">
					<td colspan="4" align="center">
						<input type="button" name="adresa_confirm" id="adresa_confirm" value="' . $text . '"' . "onclick=\"javascript: new_adresa_confirm(" . $tip ."," . $tip_loc . ",'" . $id_rezultat . "','" . $opt . "'," . $index . ",'".$adrRequired."');\"" . '/>
						<input type="button" name="adresa_cancel" id="adresa_cancel" value="' . LANG_CANCEL . '" onclick="javascript: closeMessage();" />
					</td>
				</tr>'
                . output_extra_text_modal($help_text, 4) . 
			'</table>
			</div>
		<script type="text/javascript">
			document.adresa.focus();
		</script>';
        
        if ($tip_loc != CT_ADRESA_COMANDA_INCARCARE)
            $ret .= '<span id="number_of_incarcari" style="display:none">'.$i.'</span>';
        
		echo $ret;		
		flush();
	}
	
	show_interface();		
?>